package com.woniu.controller;

import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.bcel.internal.generic.PUSH;
import com.woniu.entity.Detail;
import com.woniu.service.DetailService;
import com.woniu.uitls.ResponseUtil;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import javax.annotation.Resource;
import java.time.LocalDate;

@RestController
@RequestMapping("/detail")
public class DetailController {
    @Resource
    private DetailService detailService;
    @GetMapping("/{pageNum}/{pageSize}/{sortId}")
    public ResponseUtil findAll (@PathVariable Integer pageNum, @PathVariable Integer pageSize,@PathVariable Integer sortId){
      return   detailService.findAll(pageNum,pageSize,sortId);
    }
    @GetMapping("/{dId}")
    public ResponseUtil findById(@PathVariable Integer dId){

        return detailService.findById(dId);

    }
    @PostMapping
    public ResponseUtil add(@RequestBody Detail detail){
        detail.setCreateDate(LocalDate.now());
        return detailService.add(detail);
    }
    @DeleteMapping("/{dId}")
    public ResponseUtil delete(@PathVariable Integer dId){
        return detailService.delete(dId);
    }
    @PutMapping
    public ResponseUtil update(@RequestBody Detail detail){
        return detailService.update(detail);
    }
}
